package se.webbzon.boltzmann.game.sequence.builder.dialogue;

import se.webbzon.boltzmann.game.object.dialogue.DialogueBackground;
import se.webbzon.boltzmann.game.object.dialogue.ItemDialogue;
import se.webbzon.boltzmann.game.object.dialogue.layout.ItemDialogueLayout;
import se.webbzon.boltzmann.game.sequence.ItemDialogueSequenceNode;
import se.webbzon.boltzmann.game.sequence.Sequence;
import se.webbzon.boltzmann.game.sequence.SequenceNode;
import se.webbzon.boltzmann.game.sequence.builder.SequenceBuilder;
import se.webbzon.boltzmann.game.sequence.builder.SequenceRowDeflation;
import se.webbzon.oschi01.worldarea.WorldArea;

public class ItemDialogueRow extends AbstractDialogueRow {
	
	// The name of the sequence row
	public static final String name = "itemDialogue";
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new simple dialogue row. **/
	public ItemDialogueRow(	SequenceBuilder builder,
								ItemDialogueLayout layout, 
								DialogueBackground background,
								String text) {
		super(name,builder,layout,background,text);
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public int maxLinks() {
		return 1;
	}

	@Override public int minLinks() {
		return 0;
	}

	@Override public SequenceNode compile(WorldArea world, Sequence sequence) {
		ItemDialogueLayout layout = (ItemDialogueLayout) getLayout();
		
		ItemDialogue dialogue = 
				new ItemDialogue(layout,getBackground(),getText());
		world.createInstance(dialogue);
		return new ItemDialogueSequenceNode(sequence,dialogue);
	}

	@Override public void bind(SequenceNode node, SequenceNode[] nodes) {
		final ItemDialogueSequenceNode n = (ItemDialogueSequenceNode) node;
		if (links() == 1) { 
			Integer branch = getLink(0);
			if (branch != null)
				n.setBranch(nodes[getLink(0)]);
		}
	}

	@Override public SequenceRowDeflation getDeflation() {
		return new ItemDialogueRowDeflation(this);
	}

}
